home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / progs / thor / optconf.thor < prev    next >
Text File  |  1996-11-10  |  12KB  |  428 lines

  1. /* $VER: OptConf V1.0 (25.10.96) Shaun Downend.
  2.  *          <shaund@amiganut.demon.co.uk>
  3.  *         Optimise a conference in a BBS.
  4.  *
  5.  */
  6.  
  7.  
  8. /* Optional configuration items */
  9.  
  10. repackxpk = 1   /* during optimisation XPK packed conferences are unpacked.
  11.                  * set this to 1 to repack, or 0 to not repack.
  12.                  */
  13.  
  14. super2keep = 0  /* During optimisation the superunread flag only gets preserved as
  15.                  * an unread flag. The option allows you to mark the message as keep as well.
  16.                  */
  17.  
  18. /* End configuration */
  19.  
  20. scriptver = subword(sourceline(1), 4,1)
  21. scriptinfo = 'OptConf.thor 'scriptver' © Shaun Downend'
  22.  
  23. /*!~ "Bit numbers for message flags" */
  24.  
  25. MDB_READ          =  0   /* Message is read. */
  26. MDB_REPLIED       =  1   /* Message is replied. */
  27. MDB_PRIVATE       =  2   /* Message is private. */
  28. MDB_TO_USER       =  3   /* Message is to the user. */
  29. MDB_FROM_USER     =  4   /* Message is from the user. */
  30. MDB_DELETED       =  5   /* Message is deleted. */
  31. MDB_UNRECOVERABLE =  6   /* Message is can not be undeleted. */
  32. MDB_KEEP          =  7   /* Keep message. Message will not be deleted during conference packing. */
  33. MDB_TO_ALL        =  8   /* Message is to all. (has no reciever) */
  34. MDB_XPK_TEXT      =  9   /* Message text is Xpk'ed. (Private flag) */
  35. MDB_MARKED        = 10   /* Message is marked.  */
  36. MDB_URGENT        = 11   /* Message is urgent.  */
  37. MDB_IMPORTANT     = 12   /* Message is important. */
  38. MDB_SUPERMARKED   = 13   /* Message will not be unmarked as long as this flag is set. */
  39.  
  40. CDF_NOT_ON_BBS   = '00008000'x  /* This conference is not on the bbs. */
  41. CDB_NO_XPK_METHOD       = 13    /* Don't use any xpk method. */
  42.  
  43. /*~!*/
  44.  
  45. options results
  46. options failat 31
  47.  
  48. signal on syntax
  49. signal on halt
  50. signal on break_c
  51. signal on failure
  52.  
  53. /*!~ "Open Thor and BBSREAD ARexx ports" */
  54.  
  55. p=' '||address()||' '||show('P',,)
  56. if pos(' THOR.',p)>0 then
  57. thorport=word(substr(p,pos(' THOR.',p)+1),1)
  58. else
  59. do
  60.     say ('Thor has to be running to use this script!')
  61.     exit(0)
  62. end
  63.  
  64. if ~show('p', 'BBSREAD') then
  65. do
  66.     address command
  67.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  68.     'WaitForPort BBSREAD'
  69.     if rc ~= 0 then call errmsg('Couldn''t open BBSRead''s ARexx port.')
  70. end
  71.  
  72. address(thorport)
  73. 'VERSION STEM 'version
  74.  
  75. fullver = subword(version.THOR, 1, 1)
  76. version.thorver = substr(fullver, 1, index(fullver, '.') - 1)
  77. version.thorrev = compress(substr(fullver, index(fullver, '.') + 1), 'ß')
  78.  
  79. thorversion = version.thorver || '.' || version.thorrev
  80.  
  81. if thorversion < 2.4 then call errmsg('You need at least Thor 2.4 to run this script!')
  82.  
  83. /*~!*/
  84.  
  85. /*!~ "Get list of conference(s) to optimise" */
  86.  
  87. address(thorport)
  88.  
  89. 'currentsystem' CURRENT
  90. if(rc = 1) then call errmsg('CURRENTSYSTEM failed: No current system')
  91. if(rc = 30) then call errmsg('CURRENTSYSTEM failed: 'THOR.LASTERROR)
  92.  
  93. address BBSREAD 'getconflist bbsname "'CURRENT.BBSNAME'" stem' CONFLIST
  94. if(rc = 5) then call errmsg('GETCONFLIST failed: BBS not found')
  95. if(rc ~= 0) then call errmsg('GETCONFLIST failed: 'BBSREAD.LASTERROR)
  96.  
  97. 'requestlist instem' CONFLIST 'outstem' SELECTED 'multiselect dragselect title "Select conference(s) to optimise:"'
  98. if(rc = 5) then exit
  99. if(rc ~= 0) then call errmsg('REQUESTLIST failed: 'THOR.LASTERROR)
  100.  
  101. 'lockgui'
  102.  
  103. address(BBSREAD)
  104.  
  105. drop CONFDATA.
  106.  
  107. ptotal = 0
  108.  
  109. longest = 0
  110.  
  111. /* Work out information for progress indicator */
  112.  
  113. do i = 1 to SELECTED.COUNT
  114.  
  115.     'getconfdata bbsname "'CURRENT.BBSNAME'" confname' '"'SELECTED.i'" stem' CONFDATA
  116.     if(rc = 7) then call errmsg('GETCONFDATA failed: Conference not found')
  117.     if(rc ~= 0) then call errmsg('GETCONFDATA failed: 'BBSREAD.LASTERROR)
  118.  
  119.     /* find the longest conference name to fix width of progress indicator */
  120.     if length(SELECTED.i) > longest then longest = length(SELECTED.i)
  121.  
  122.     /* find out if the conference is xpk packed, if so then this requires another step */
  123.     if CONFDATA.XPKMETHOD ~= '' & ~bittst(CONFDATA.FLAGS,CDB_NO_XPK_METHOD) then xpk = 10000
  124.     else xpk = 0
  125.  
  126.     /* total of progress indicator is xpk + create conf (10000) + copy msgs (10000)
  127.      * + pack conf (10000) + delete msgs (10000) + delete conf (10000).
  128.      * 10000 is used (a large value) to reduce inaccuracies on division later on.
  129.      */
  130.     ptotal = ptotal + xpk + 60000
  131. end
  132.  
  133. longest = length('Copying messages in ') + longest + length('to ') + longest + length('.temp')
  134.  
  135. /* open and fix progress indicator width */
  136. call oprog(scriptinfo,ptotal,center('...Starting OptConf.thor...Initialising script...',longest,' '))
  137.  
  138. pcurrent = 0
  139.  
  140. 'bufmode copyback'      /* Turn on copyback mode  */
  141.  
  142. /*~!*/
  143.  
  144. /*!~ "Main loop" */
  145. do n = 1 to SELECTED.COUNT
  146.  
  147.     conference = SELECTED.n
  148.  
  149.     tempconf  = conference'.temp'
  150.  
  151.     call getmsginfo(conference) /* get msg numbers for selected conference */
  152.  
  153.     xpkpack = 0
  154.     /* is conference xpk packed? */
  155.     if CONFDATA.XPKMETHOD ~= '' & ~bittst(CONFDATA.FLAGS,CDB_NO_XPK_METHOD) then xpkpack = 1
  156.  
  157.     call uprog(window,pcurrent,'Creating temporary conference 'tempconf'...')
  158.  
  159.     pcurrent = pcurrent + 10000
  160.  
  161.     /* create temporary conference */
  162.     'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" set' c2x(CDF_NOT_ON_BBS)
  163.     if(rc ~= 0) then call errmsg('CONFIGCONF failed: 'BBSREAD.LASTERROR)
  164.  
  165.     call copyconf(conference,tempconf) /* copy msgs from orig conf to temp conf */
  166.  
  167.     /*!~ "Delete messages in original conference" */
  168.     call uprog(window,pcurrent,'Deleting messages in 'conference)
  169.  
  170.     pstart = pcurrent
  171.  
  172.     if (CONFDATA.LASTMSG - CONFDATA.FIRSTMSG) ~= 0 then /* is conference empty? */
  173.     do
  174.         pinc = 10000 %  (CONFDATA.LASTMSG -  CONFDATA.FIRSTMSG)
  175.  
  176.         do i= CONFDATA.FIRSTMSG to CONFDATA.LASTMSG
  177.  
  178.             drop OLDMSGDATA.
  179.  
  180.             if (pcurrent // 10 = 0) then call uprog(window,pcurrent)
  181.  
  182.             pcurrent = pcurrent + pinc
  183.  
  184.             'readbrmessage "'CURRENT.BBSNAME'"' '"'conference'"' i 'datastem' OLDMSGDATA
  185.             if(rc ~= 0) then call bbsreaderr
  186.  
  187.             if ~bittst(OLDMSGDATA.FLAGS,MDB_DELETED) then /* is message already deleted? */
  188.             do
  189.                 'updatebrmessage "'CURRENT.BBSNAME'"' '"'conference'"' i 'setdeleted'
  190.                 if(rc ~= 0) then call bbsreaderr
  191.             end
  192.         end
  193.         pcurrent = pstart + 10000 /* adjust to fix any inaccuracies in previous division :-) */
  194.     end
  195.     else /* conference is empty so skip */
  196.     do
  197.         pinc = pstart + 10000
  198.         call uprog(window,pcurrent)
  199.     end
  200.     /*~!*/
  201.  
  202.     /*!~ "Pack original conference" */
  203.  
  204.     call uprog(window,pcurrent,'Clearing 'conference'...')
  205.  
  206.     pcurrent = pcurrent + 10000
  207.  
  208.     'packdatafile "'CURRENT.BBSNAME'" confname' '"'conference'"'
  209.     if(rc ~= 0) then call errmsg('PACKDATAFILE failed: 'BBSREAD.LASTERROR)
  210.     /*~!*/
  211.  
  212.     call getmsginfo(tempconf) /* get msg numbers for temp conf */
  213.  
  214.     call copyconf(tempconf,conference) /* copy msgs from temp conf to orig conf */
  215.  
  216.     /*!~ "Delete temporary conference" */
  217.     call uprog(window,pcurrent,'Deleting 'tempconf'...')
  218.  
  219.     pcurrent = pcurrent + 10000
  220.  
  221.     'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" deleteconf'
  222.     if(rc ~= 0) then call errmsg('CONFIGCONF failed: 'BBSREAD.LASTERROR)
  223.  
  224.     /*~!*/
  225.  
  226.     /*!~ "Repack XPK packed conference" */
  227.     if repackxpk = 1 then
  228.     do
  229.         if xpkpack = 1 then
  230.         do  /* If conference was xpk-packed then pack it */
  231.             call uprog(window,pcurrent,'XPK Packing 'conference'...')
  232.  
  233.             pcurrent = pcurrent + 10000
  234.  
  235.             address(BBSREAD)
  236.             'packdatafile "'CURRENT.BBSNAME'" confname' '"'conference'"'
  237.             if(rc ~= 0) then call errmsg('PACKDATAFILE failed: 'BBSREAD.LASTERROR)
  238.  
  239.         end
  240.     end
  241.     /*~!*/
  242.  
  243. end
  244.  
  245. call uprog(window,pcurrent,'Complete.')
  246. do i = 1 to 600
  247. end
  248.  
  249. pcurrent = pcurrent + 10000
  250.  
  251. /*!~ "Notify completion, update conf window, cleanup" */
  252. address(thorport)
  253. 'updateconfwindow'
  254. 'unlockgui'
  255. address(bbsread)
  256. 'bufmode endcopyback'
  257. call cprog(window)
  258. address(thorport)
  259. 'requestnotify "OptConf.thor complete!"' '" _OK "'
  260. if(rc = 30) then say THOR.LASTERROR
  261.  
  262. exit
  263. /*~!*/
  264.  
  265. /*~!*/
  266.  
  267. /*!~ "Copy all messages from one conference to another conference " */
  268. copyconf:
  269.  
  270. parse arg fromconf,toconf
  271.  
  272. call uprog(window,pcurrent,'Copying messages in 'fromconf 'to 'toconf)
  273.  
  274. pstart = pcurrent
  275.  
  276. if (CONFDATA.LASTMSG - CONFDATA.FIRSTMSG) ~= 0 then /* is conference empty? */
  277. do
  278.     pinc = 10000 % (CONFDATA.LASTMSG -  CONFDATA.FIRSTMSG)
  279.  
  280.     do i= CONFDATA.FIRSTMSG to CONFDATA.LASTMSG
  281.  
  282.         drop MSGTAGS.
  283.         drop MSGDATA.
  284.  
  285.         if (pcurrent // 10 = 0) then call uprog(window,pcurrent)
  286.  
  287.         pcurrent = pcurrent + pinc
  288.  
  289.         'readbrmessage "'CURRENT.BBSNAME'"' '"'fromconf'"' i 'headstem' MSGTAGS 'textstem' MSGTAGS 'datastem' MSGDATA
  290.         if(rc ~= 0) then call bbsreaderr
  291.  
  292.         if ~bittst(MSGDATA.FLAGS,MDB_DELETED) | ~bittst(MSGDATA.FLAGS,MDB_UNRECOVERABLE) then
  293.         do
  294.             exargs = ''
  295.             if ~bittst(MSGDATA.FLAGS,MDB_MARKED)   then exargs = exargs || ' DONTMARKMESSAGE'
  296.             if bittst(MSGDATA.FLAGS,MDB_PRIVATE)   then exargs = exargs || ' PRIVATE'
  297.             if bittst(MSGDATA.FLAGS,MDB_READ)      then exargs = exargs || ' READ'
  298.             if bittst(MSGDATA.FLAGS,MDB_URGENT)    then exargs = exargs || ' URGENT'
  299.             if bittst(MSGDATA.FLAGS,MDB_IMPORTANT) then exargs = exargs || ' IMPORTANT'
  300.  
  301.             'writebrmessage "'CURRENT.BBSNAME'"' '"'toconf'" stem' MSGTAGS exargs
  302.             if(rc ~= 0) then call bbsreaderr
  303.  
  304.             msgnr = result
  305.  
  306.             exargs = ''
  307.  
  308.             if bittst(MSGDATA.FLAGS,MDB_KEEP)    then exargs = exargs || ' SETKEEP'
  309.  
  310.             if super2keep = 1 then
  311.             do
  312.                 if bittst(MSGDATA.FLAGS,MDB_SUPERMARKED) & ~bittst(MSGDATA.FLAGS,MDB_KEEP) then exargs = exargs || ' SETKEEP'
  313.             end
  314.  
  315.             if bittst(MSGDATA.FLAGS,MDB_REPLIED) then exargs = exargs || ' SETREPLIED'
  316.             if MSGDATA.HAZELEVEL ~= 0 then exargs = exargs || ' HAZELEVEL ' || MSGDATA.HAZELEVEL
  317.  
  318.             if exargs ~= '' then 'updatebrmessage "'CURRENT.BBSNAME'"' '"'toconf'"' msgnr exargs
  319.             if(rc ~= 0) then call bbsreaderr
  320.  
  321.         end
  322.         /*
  323.         else say 'Message deleted or unrecoverable'
  324.         */
  325.     end
  326.     pcurrent = pstart + 10000 /* adjust for any inaccuracies in previous division :-) */
  327. end
  328. else /* conference is empty so skip it */
  329. do
  330.     pinc = pstart + 10000
  331.     call uprog(window,pcurrent)
  332. end
  333.  
  334. return
  335. /*~!*/
  336.  
  337. /*!~ "Get message numbers for a conference" */
  338. getmsginfo:
  339. parse arg conf
  340.  
  341. drop CONFDATA.
  342.  
  343. 'getconfdata bbsname "'CURRENT.BBSNAME'" confname' '"'conf'" stem' CONFDATA
  344. if(rc = 7) then call errmsg('GETCONFDATA failed: Conference not found')
  345. if(rc ~= 0) then call errmsg('GETCONFDATA failed: 'BBSREAD.LASTERROR)
  346.  
  347. return
  348. /*~!*/
  349.  
  350. /*!~ "Progress indication" */
  351.  
  352. /*!~ "Open progress indicator" */
  353. oprog:
  354. parse arg ptitle,ptotal,ptxt
  355. address(thorport)
  356. 'openprogress title "'ptitle'" total' ptotal 'pt "'ptxt'"'
  357. if(rc ~= 0) then call errmsg(THOR.LASTERROR,10)
  358. else window = result
  359. return
  360. /*~!*/
  361.  
  362. /*!~ "Update progress indicator" */
  363. uprog:
  364. parse arg pwindow,pcurrent,ptxt
  365. /*
  366. say 'current 'pcurrent
  367. */
  368. if ptxt = '' then ptxt = ''
  369. else ptxt = 'pt ' || '"'ptxt'"'
  370. address(thorport)
  371. 'updateprogress req' pwindow 'current' pcurrent ptxt
  372. if(rc~=0) then signal cleanup
  373. return(0)
  374. /*~!*/
  375.  
  376. /*!~ "Close Progress indicator" */
  377. cprog:
  378. parse arg pwindow
  379. address(thorport)
  380. 'closeprogress req' pwindow
  381. return
  382. /*~!*/
  383.  
  384. /*~!*/
  385.  
  386. /*!~ "Error handling" */
  387. break_c:
  388.  
  389. call errmsg('User break!')
  390.  
  391. error:
  392. halt:
  393. failure:
  394.  
  395. if rc ~= 0 then call errmsg('+++ Line 'sigl' returned 'rc': 'errortext(rc))
  396.  
  397. cleanup:
  398.  
  399. address(bbsread)
  400. 'bufmode endcopyback'
  401. if window ~= 'WINDOW' then call cprog(window)
  402. address(thorport)
  403. 'unlockgui'
  404. exit(0)
  405.  
  406. errmsg:
  407. parse arg msgtxt
  408. address(thorport)
  409. 'requestnotify "'msgtxt'"' '" _OK "'
  410. if(rc = 30) then say THOR.LASTERROR
  411. signal cleanup
  412. return
  413.  
  414. bbsreaderr:
  415. address(bbsread)
  416. 'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" deleteconf'
  417. if(rc ~= 0) then
  418. do
  419.     address(thorport)
  420.     'requestnotify "CONFIGCONF failed: 'BBSREAD.LASTERROR'\nFailed to delete temporary conference."' '" _OK "'
  421. end
  422. address(thorport)
  423. 'requestnotify "BBSRead Error: 'BBSREAD.LASTERROR'\nThere appears to be a problem with the database.\nPlease repair the database before running this script."' '" _OK "'
  424. signal cleanup
  425. return
  426. /*~!*/
  427.  
  428.